package com.example.demo.utils;

import java.util.Random;

public class ValidateCodeUtils {
    public static Integer generateValidateCode(int length){
        Integer code=null;
        if(length==4){
            code=new Random().nextInt(999);
            if(code<1000){
                code=code+1000;
            }
        }else if(length==6){
            code=new Random().nextInt(999999);
            if(code<1000000){
                code=code+1000000;
            }
        }else{
            throw new RuntimeException("只能生成4位或6位的数字");
        }
        return code;

        }
    public static String generateValidateCode4String(int length){
        Random rdm = new Random();
        String hash1 = Integer.toHexString(rdm.nextInt());
        String capstr = hash1.substring(0, length);
        return capstr;
    }
    }

